//
//  XinJIanSJViewController.m
//  ZhiBoYuan
//
//  Created by coder_di on 2018/4/24.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "XinJIanSJViewController.h"

@interface XinJIanSJViewController ()
@property (nonatomic, strong)UITextField *yinhangkaTextField;

@end

@implementation XinJIanSJViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    // Do any additional setup after loading the view.
    
    
    UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(20 * KscreenWidth, 30 * KscreenHeight + NAVIGATION_BAR_HEIGHT, 100 * KscreenWidth, 30 *KscreenHeight)];
    lable.text = @"试卷名称";
    lable.font = [UIFont systemFontOfSize:18 * KscreenWidth];
    [self.view addSubview:lable];
    
    _yinhangkaTextField = [[UITextField alloc]initWithFrame:CGRectMake(120 * KscreenWidth, 30 * KscreenHeight + NAVIGATION_BAR_HEIGHT, ScreenWidth - 140 * KscreenWidth, 30 * KscreenHeight)];
    _yinhangkaTextField.font = [UIFont systemFontOfSize:18 * KscreenWidth];
    _yinhangkaTextField.placeholder = @"请输入试卷名称";
    [self.view addSubview:_yinhangkaTextField];
    
    UIView *line = [[UIView alloc]initWithFrame:CGRectMake(20 * KscreenWidth, 80 * KscreenHeight + NAVIGATION_BAR_HEIGHT, ScreenWidth - 40 * KscreenWidth, 1 * KscreenHeight)];
    line.backgroundColor = ZhuTiColor;
    [self.view addSubview:line];
    
    UIButton *okBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    okBtn.frame = CGRectMake(20 * KscreenWidth, 300 * KscreenHeight, ScreenWidth - 40 * KscreenWidth, 50 * KscreenHeight);
    okBtn.backgroundColor = ZhuTiColor;
    [okBtn addTarget:self action:@selector(okBtnAction) forControlEvents:(UIControlEventTouchUpInside)];
    [okBtn setTitle:@"确认" forState:0];
    [self.view addSubview:okBtn];
    
}

-(void)okBtnAction{
    SGParameter *parameter  = [[SGParameter alloc] init];
    parameter.body = @{@"task_id":_teskID,
                       @"name":_yinhangkaTextField.text
                       };
    
    [SGHttpTool POST:[NSString stringWithFormat:@"%@g=Client&m=Paper&a=addTaskPaper",HTTPP] parameter:parameter sucess:^(id responseObject) {
        NSLog(@"%@",responseObject);
        
        if ([responseObject[@"status"] intValue] == 200) {
            [MBProgressHUD showTextOnly:self.view message:@"创建成功" delay:2.0];
            
            
            NSString *str = _yinhangkaTextField.text;
           self.backback(str);
            
            [self.navigationController popViewControllerAnimated:YES];
            
        }else{
            [MBProgressHUD showTextOnly:self.view message:responseObject[@"msg"] delay:2.0];
            
        }
        
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
        
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
